package com.ld.control.utils;


import com.alibaba.fastjson.JSONObject;
import com.ld.control.business.process.model.ProcessNodeExampleModel;
import com.ld.control.business.process.model.ProcessNodeParamExampleModel;
import com.ld.control.common.equipment.method.HuiLinEquipmentSystemMethod;
import com.ld.control.common.equipment.method.OBRobotEquipmentSystemMethod;
import com.ld.control.common.equipment.method.PHEquipmentSystemMethod;
import com.ld.control.common.equipment.param.HuiLingRobotMethodParamConstant;
import com.ld.control.common.equipment.param.OBRobotMethodParamConstant;
import com.ld.control.common.equipment.param.PHMethodParamConstant;
import com.ld.control.common.vo.EquipmentSystemMethodVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Slf4j
@Component
public class EquipmentSystemMethodUtils {

    @Autowired
    private PHEquipmentSystemMethod phEquipmentSystemMethod;

    @Autowired
    private OBRobotEquipmentSystemMethod obRobotEquipmentSystemMethod;

    @Autowired
    private HuiLinEquipmentSystemMethod huiLinEquipmentSystemMethod;

    public EquipmentSystemMethodVo equipmentSystemMethodMapping(Long processNodeExampleRunningModelId, ProcessNodeExampleModel processNodeExampleModel,
                                                                List<ProcessNodeParamExampleModel> processNodeParamExampleModelList) {
        log.info("equipmentSystemMethodMapping_LOG\n{}",JSONObject.toJSONString(processNodeParamExampleModelList));

        EquipmentSystemMethodVo equipmentSystemMethodVo = null;
        Map<String, ProcessNodeParamExampleModel> processNodeParamExampleModeMap = processNodeParamExampleModelList.stream()
                .collect(Collectors.toMap(ProcessNodeParamExampleModel::getName, Function.identity()));
        ///////////////////// PH //////////////////////
        if (processNodeExampleModel.getNodeName().equals(PHMethodParamConstant.RunMethod.internalMethodName)) {
            equipmentSystemMethodVo = phEquipmentSystemMethod.PHRunMethod(processNodeExampleRunningModelId, processNodeParamExampleModeMap);
        }

        ///////////////////// 傲博机械臂 //////////////////////
        if (processNodeExampleModel.getNodeName().equals(OBRobotMethodParamConstant.Pick.internalMethodName)) {
            equipmentSystemMethodVo = obRobotEquipmentSystemMethod.get_Pick_OB_Ext(processNodeExampleRunningModelId, processNodeParamExampleModeMap);
        }
        if (processNodeExampleModel.getNodeName().equals(OBRobotMethodParamConstant.Place.internalMethodName)) {
            equipmentSystemMethodVo = obRobotEquipmentSystemMethod.get_Place_OB_Ext(processNodeExampleRunningModelId, processNodeParamExampleModeMap);
        }
        if (processNodeExampleModel.getNodeName().equals(OBRobotMethodParamConstant.SingleAction.internalMethodName)) {
            equipmentSystemMethodVo = obRobotEquipmentSystemMethod.get_SingleAction_OB_Ext(processNodeExampleRunningModelId, processNodeParamExampleModeMap);
        }
        if (processNodeExampleModel.getNodeName().equals(OBRobotMethodParamConstant.DoubleAction.internalMethodName)) {
            equipmentSystemMethodVo = obRobotEquipmentSystemMethod.get_DoubleAction_OB_Ext(processNodeExampleRunningModelId, processNodeParamExampleModeMap);
        }
        if (processNodeExampleModel.getNodeName().equals(OBRobotMethodParamConstant.Agv_Move.internalMethodName)) {
            equipmentSystemMethodVo = obRobotEquipmentSystemMethod.get_Agv_Move_OB_Ext(processNodeExampleRunningModelId, processNodeParamExampleModeMap);
        }

        if (processNodeExampleModel.getNodeName().equals(OBRobotMethodParamConstant.Track_Move.internalMethodName)) {
            equipmentSystemMethodVo = obRobotEquipmentSystemMethod.get_Track_Move_Ext(processNodeExampleRunningModelId, processNodeParamExampleModeMap);
        }


        ///////////////////// 慧灵四轴机械臂 //////////////////
        if (processNodeExampleModel.getNodeName().equals(HuiLingRobotMethodParamConstant.Pick.internalMethodName)) {
            equipmentSystemMethodVo = huiLinEquipmentSystemMethod.getHui_Ling_Pick_Ext(processNodeExampleRunningModelId, processNodeParamExampleModeMap);
        }
        if (processNodeExampleModel.getNodeName().equals(HuiLingRobotMethodParamConstant.Place.internalMethodName)) {
            equipmentSystemMethodVo = huiLinEquipmentSystemMethod.getHui_Ling_Place_Ext(processNodeExampleRunningModelId, processNodeParamExampleModeMap);
        }
        if (processNodeExampleModel.getNodeName().equals(HuiLingRobotMethodParamConstant.SingleAction.internalMethodName)) {
            equipmentSystemMethodVo = huiLinEquipmentSystemMethod.getHui_Ling_SingleAction_Ext(processNodeExampleRunningModelId, processNodeParamExampleModeMap);
        }
        if (processNodeExampleModel.getNodeName().equals(HuiLingRobotMethodParamConstant.DoubleAction.internalMethodName)) {
            equipmentSystemMethodVo = huiLinEquipmentSystemMethod.getHui_Ling_DoubleAction_Ext(processNodeExampleRunningModelId, processNodeParamExampleModeMap);
        }
        log.info("\n================equipmentSystemMethodMapping================\n{}", JSONObject.toJSONString(equipmentSystemMethodVo));
        return equipmentSystemMethodVo;
    }

}
